package GreedyAlgorithmPackage2;

import java.util.Arrays;

/**
 * @author Lzm
 * @version 1.0
 */
public class findContentChildren_ {

  public int findContentChildren(int[] g, int[] s) {
    if(g == null || s == null || g.length == 0 || s.length == 0){
      return 0;
    }
    Arrays.sort(g);
    Arrays.sort(s);
    int count = 0;
    int children = 0 ;
    int cookie = 0;
    for (children = 0 , cookie = 0; children < g.length && cookie < s.length;){
      if (g[children] <= s[cookie]){
        count++;
        children++;
        cookie++;
      }
      else{
        cookie++;
      }
    }
    return count;
  }
}
